import vue3TreeOrg from 'vue3-tree-org';
import 'vue3-tree-org/lib/vue3-tree-org.css';
import { createApp } from 'vue';
import App from './App.vue';
import ElementPlus from 'element-plus';
import '@x-tech/fe-puma-starter-theme-new-plus/lib/index.css';
import './styles/index.scss';
import router from '@/router';
import store from '@/store';
import 'virtual:svg-icons-register';
import * as ElIcon from '@element-plus/icons-vue';
import '@/assets/iconfont/iconfont.css';
import limitNumber from '@/directives/limitNumber';
import * as packagejson from '../package.json';
import svgIcon from './components/SvgIcon.vue';
import { $btnAuth } from '@/utils/common';
import * as sentryPlugin from '@x-tech/fe-puma-lib-sentry-config/dist/vuePlugin';
import { traceInitVue, tracePlugin } from '@x-tech/fe-trace-sdk-web';

// ---------------------- 路由拦截 方法 -----------------------------------//
const whiteList = ['/login', '/wxLogin'];
router.beforeEach((to, from, next) => {
    const token = store.state.puma.token;
    console.log(to.path);
    if (!token.trim() && !whiteList.includes(to.path)) {
        next('/login');
    } else {
        next();
    }
});
export const tracer = traceInitVue('app', {
    productCode: 'PINMEI',
    productVersion: packagejson.version, // 会自动获取你package.json里面的version 所以每次发版本时需手动更新一下这个参数
    env: window.XCConfig.VUE_APP_ENV,
    vueVersion: 'vue3.x',
});
const app = createApp(App);
app.use(sentryPlugin);
app.use(tracePlugin, { tracer });
for (const iconName in ElIcon) {
    app.component(iconName, ElIcon[iconName]);
}
app.component('SvgIcon', svgIcon);
app.config.globalProperties.$btnAuth = $btnAuth;

app.use(store).use(router).use(ElementPlus).use(vue3TreeOrg).use(limitNumber).mount('#app');
